package com.heima.article.listener;


import com.alibaba.fastjson.JSON;
import com.heima.article.service.HotArticleService;
import com.heima.article.stream.HotArticleStream;
import com.heima.common.constants.HotArticleConstants;
import com.heima.model.message.ArticleVisitStreamMess;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import springfox.documentation.spring.web.json.Json;

/**
 * 监听流式计算之后的结果的监听类
 */
@Component
public class HotArticleIncrHandleListener {

    @Autowired
    private HotArticleService hotArticleService;

    /**
     * 监听结果之后的方法
     */
    @KafkaListener(topics = HotArticleConstants.HOT_ARTICLE_INCR_HANDLE_TOPIC)
    public void getMessage(String message){
        //1.转化类型
        ArticleVisitStreamMess mess = JSON.parseObject(message, ArticleVisitStreamMess.class);

        //2.执行重新计算
        hotArticleService.computeHotArticleIncrHandle(mess);
    }
}
